/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bio.jpa.entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Diego
 */
@Entity
@Table(name = "user_has_group", catalog = "biodb", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "UserHasGroup.findAll", query = "SELECT u FROM UserHasGroup u"),
    @NamedQuery(name = "UserHasGroup.findByUidFk", query = "SELECT u FROM UserHasGroup u WHERE u.userHasGroupPK.uidFk = :uidFk"),
    @NamedQuery(name = "UserHasGroup.findByGidFk", query = "SELECT u FROM UserHasGroup u WHERE u.userHasGroupPK.gidFk = :gidFk"),
    @NamedQuery(name = "UserHasGroup.findByLastUpdate", query = "SELECT u FROM UserHasGroup u WHERE u.lastUpdate = :lastUpdate")})
public class UserHasGroup implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected UserHasGroupPK userHasGroupPK;
    @Basic(optional = false)
    @Column(name = "last_update")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastUpdate;
    @JoinColumn(name = "uid_fk", referencedColumnName = "user_id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User user;
    @JoinColumn(name = "gid_fk", referencedColumnName = "gr_id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private UserGroup userGroup;

    public UserHasGroup() {
    }

    public UserHasGroup(UserHasGroupPK userHasGroupPK) {
        this.userHasGroupPK = userHasGroupPK;
    }

    public UserHasGroup(UserHasGroupPK userHasGroupPK, Date lastUpdate) {
        this.userHasGroupPK = userHasGroupPK;
        this.lastUpdate = lastUpdate;
    }

    public UserHasGroup(int uidFk, int gidFk) {
        this.userHasGroupPK = new UserHasGroupPK(uidFk, gidFk);
    }

    public UserHasGroupPK getUserHasGroupPK() {
        return userHasGroupPK;
    }

    public void setUserHasGroupPK(UserHasGroupPK userHasGroupPK) {
        this.userHasGroupPK = userHasGroupPK;
    }

    public Date getLastUpdate() {
        return lastUpdate;
    }

    public void setLastUpdate(Date lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public UserGroup getUserGroup() {
        return userGroup;
    }

    public void setUserGroup(UserGroup usergroup) {
        this.userGroup = usergroup;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userHasGroupPK != null ? userHasGroupPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UserHasGroup)) {
            return false;
        }
        UserHasGroup other = (UserHasGroup) object;
        if ((this.userHasGroupPK == null && other.userHasGroupPK != null) || (this.userHasGroupPK != null && !this.userHasGroupPK.equals(other.userHasGroupPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.bio.jpa.entities.UserHasGroup[ userHasGroupPK=" + userHasGroupPK + " ]";
    }
    
}
